<?php

/**
 * This is the model class for table "empleados".
 *
 * The followings are the available columns in table 'empleados':
 * @property string $dni
 * @property string $nombres
 * @property string $apellidos
 * @property string $email_personal
 * @property string $email_empresa
 * @property integer $PERFILES_id
 * @property integer $actividad
 * @property string $telefonos
 * @property string $fecha_nacimiento
 *
 * The followings are the available model relations:
 * @property Asistencias[] $asistenciases
 * @property Autenticacion[] $autenticacions
 * @property Comisiones[] $comisiones
 * @property Perfiles $pERFILES
 * @property Ventas[] $ventases
 */
class Empleados extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Empleados the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'empleados';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('dni, nombres, apellidos, email_personal, email_empresa, PERFILES_id, actividad, fecha_nacimiento', 'required'),
			array('PERFILES_id, actividad', 'numerical', 'integerOnly'=>true),
			array('dni, nombres, apellidos, email_personal, email_empresa', 'length', 'max'=>45),
			array('telefonos', 'length', 'max'=>50),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('dni, nombres, apellidos, email_personal, email_empresa, PERFILES_id, actividad, telefonos, fecha_nacimiento', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'asistenciases' => array(self::HAS_MANY, 'Asistencias', 'EMPLEADOS_dni'),
			'autenticacions' => array(self::HAS_MANY, 'Autenticacion', 'EMPLEADOS_dni'),
			'comisiones' => array(self::HAS_MANY, 'Comisiones', 'EMPLEADOS_dni'),
			'pERFILES' => array(self::BELONGS_TO, 'Perfiles', 'PERFILES_id'),
			'ventases' => array(self::HAS_MANY, 'Ventas', 'EMPLEADOS_dni'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'dni' => 'Dni',
			'nombres' => 'Nombres',
			'apellidos' => 'Apellidos',
			'email_personal' => 'Email Personal',
			'email_empresa' => 'Email Empresa',
			'PERFILES_id' => 'Perfiles',
			'actividad' => 'Actividad',
			'telefonos' => 'Telefonos',
			'fecha_nacimiento' => 'Fecha Nacimiento',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('dni',$this->dni,true);
		$criteria->compare('nombres',$this->nombres,true);
		$criteria->compare('apellidos',$this->apellidos,true);
		$criteria->compare('email_personal',$this->email_personal,true);
		$criteria->compare('email_empresa',$this->email_empresa,true);
		$criteria->compare('PERFILES_id',$this->PERFILES_id);
		$criteria->compare('actividad',$this->actividad);
		$criteria->compare('telefonos',$this->telefonos,true);
		$criteria->compare('fecha_nacimiento',$this->fecha_nacimiento,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}